package cn.kgc.vue.service.impl;

import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.commons.ResponseResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.vue.entity.LogInfo;
import cn.kgc.vue.service.LogInfoService;
import cn.kgc.vue.mapper.LogInfoMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
* @author mengshun
* @description 针对表【sys_log_info】的数据库操作Service实现
* @createDate 2023-12-15 13:44:22
*/
@Service
public class LogInfoServiceImpl extends ServiceImpl<LogInfoMapper, LogInfo>implements LogInfoService{


    @Override
    public ResponseResult getLogsList(QueryCondition<LogInfo> queryCondition) {


        Page<LogInfo> logInfoPage = new Page<>(queryCondition.getPage(), queryCondition.getLimit());
        LogInfo query = queryCondition.getQuery();

        //  ip  user  model
        LambdaQueryWrapper<LogInfo> lambda = new QueryWrapper<LogInfo>().lambda();
        lambda.eq(StringUtils.isNotEmpty(query.getIp()),LogInfo::getIp,query.getIp())
                .eq(StringUtils.isNotEmpty(query.getUsername()),LogInfo::getUsername,query.getUsername())
                .eq(StringUtils.isNotEmpty(query.getModel()),LogInfo::getModel,query.getModel())
                .orderByDesc(LogInfo::getCreateTime);

        baseMapper.selectPage(logInfoPage,lambda);

        HashMap<String, Object> result = new HashMap<>();
        result.put("total",logInfoPage.getTotal());
        result.put("pageData",logInfoPage.getRecords());

        return ResponseResult.success().data(result);
    }
}




